<template>
    <div class="check-accounts">
        <div class="row white-box">
            <div class="col-md-12 p-0">
                <div class="input-group">
                    <date-button :range="true" :defaultToNow="true" v-model="date"></date-button>
                    <span class="input-group-btn">
                              <button class="btn btn-info" type="button" @click="go">go</button>
                        </span>
                </div>
            </div>
            <div class="col-md-12 p-0">
                <input type="file" class="dropify" @change="getFile($event)" />
            </div>
        </div>
    </div>
</template>

<script>
    import DateButton from '@/components/widgets/Datepicker/DateButton'
    import {checkAccounts} from '@/api/bill'
    export default {
        name: "CheckAccounts",
        components: {DateButton},
        mounted() {
            //$('.dropify').dropify();
        },
        data() {
            return {
                date: ''
            }
        },
        methods: {
            go() {
                this.upload()
            },
            getFile() {
                this.file = event.target.files[0]
            },
            upload() {
                if (!this.file.name) {
                    return $.toast({
                        heading: 'please select file',
                        position: 'top-right',
                        loaderBg: '#ff6849',
                        icon: 'error',
                    })
                }

                let extension = this.file.name.split('.')[1]

                if (extension !== 'xlsx' && extension !== 'xls') {
                    return $.toast({
                        heading: 'unsupported file',
                        position: 'top-right',
                        loaderBg: '#ff6849',
                        icon: 'error',
                    })
                }

                let param = new FormData(); //创建form对象
                param.append('file', this.file, this.file.name) //通过append向form对象添加数据
                param.append('name', this.file.name)

                checkAccounts(this.date, param).then(res => {
                    console.log(res)
                })
            },
        }
    }
</script>

<style scoped>

</style>